package router

import (
	"cloud-storage/controller"
	"cloud-storage/lib"
	"cloud-storage/middleware"
	"cloud-storage/pkg/logger"
	"cloud-storage/utils"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))

	//发送验证码
	r.GET("api/v1/sendSms/:phone", controller.SendSmsCode)
	//注册
	r.POST("/api/v1/register", controller.Register)
	//验证码登录
	r.POST("/api/v1/loginSms", controller.LoginWithSms)
	//密码登录
	r.POST("/api/v1/loginPw", controller.LoginWithPassword)
	r.StaticFS("/upload/images", http.Dir(utils.GetFullPath(lib.ImagesSetting.ImagePath)))
	//r.GET("/downloadFile", controller.DownloadFile)
	r.GET("/file/sharePass", controller.SharePass)
	r.GET("/file/shareDownload", controller.DownloadShareFile)
	//创建路由组，并使用中间件
	v1 := r.Group("/api/v1", middleware.JWTAuth())
	{
		//添加密码
		v1.POST("/updatePassword", controller.UpdatePassword)
		//更新用户名
		v1.GET("/updateName", controller.UpdateName)
		//更新头像
		v1.PUT("/updateImg", controller.UpdateImage)
		//获取头像
		v1.GET("/getImg", controller.GetImage)
	}
	{
		v1.GET("/index", controller.Index)
		v1.GET("/files", controller.Files)
		v1.GET("/doc-files", controller.DocFiles)
		v1.GET("/image-files", controller.ImageFiles)
		v1.GET("/video-files", controller.VideoFiles)
		v1.GET("/music-files", controller.MusicFiles)
		v1.GET("/other-files", controller.OtherFiles)
		v1.GET("/downloadFile", controller.DownloadFile)
		v1.GET("/shareFile", controller.ShareFile)
		v1.POST("/createFolder", controller.AddFolder)
		v1.POST("/createFile", controller.HandlerUpload)
		v1.DELETE("/deleteFileOss", controller.DeleteFileOss)
		v1.DELETE("/deleteFolder", controller.DeleteFileFolder)
		v1.PUT("/updateFolder", controller.UpdateFileFolder)
	}
	return r

}
